package com.itheima.dubbo.web;

import com.itheima.dubbo.UserFace;
import com.itheima.dubbo.pojo.Student;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class UserController {
    /**
     * timeout  设置超时时间
     * version  设置版本
     * retries  设置重试次数
     * loadbalance 设置负载均衡机制
     */
    @DubboReference(timeout = 2000,version = "1.0.0",retries = 0,loadbalance = "random")
    UserFace userFace;

    /**
     * 测试Dubbo框架
     * @return
     */
    @GetMapping("hello")
    public String hello(){
        return userFace.hello("周杰伦");
    }

    /**
     * 根据id查询学生对象
     * @return
     */
    @GetMapping("findByStuId")
    public Student findStuById(){
        return  userFace.findById(Student.builder().id(1).name("周杰伦").age(20).build());
    }
}
